<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition >

	<div align="center">
		<h:form id="search">

			<h:panelGrid id="search" columns="4">
				<h:outputLabel value="Tytuł" for="title" />
				<h:inputText id="title" value="#{searchBean.bookToSearch.title}"
					immediate="true" />

				<h:outputLabel value="Autor" for="author" />
				<h:inputText id="author" value="#{searchBean.bookToSearch.author}"
					immediate="true" />

				<h:outputLabel value="Wydawnictwo" for="publisher" />
				<h:inputText id="publisher"
					value="#{searchBean.bookToSearch.publisher}" immediate="true" />

				<h:outputLabel value="Rok wydania" for="publicationYear" />
				<h:inputText id="publicationYear"
					value="#{searchBean.bookToSearch.publicationYear}" immediate="true" />

				<h:outputLabel value="Kategorie" for="category" />
				<h:selectOneMenu id="category" immediate="true" value="#{searchBean.bookToSearch.categories}">
				
					<f:selectItems value="#{userBean.bookCategories}" />
				</h:selectOneMenu>

				<h:outputLabel value="Repozytorium" for="repository" />
				<h:selectOneMenu id="repository" value="#{searchBean.selectedRepo}"
					immediate="true">
					<f:converter converterId="repoConverter" />
					<f:selectItem value="#{searchBean.item}" itemLabel="" />
					<f:selectItems value="#{searchBean.repoList}" var="repo"
						itemLabel="#{repo.name}" itemValue="#{repo}" />
				</h:selectOneMenu>


				<h:commandButton value="Szukaj" action="#{searchBean.search}"/>

			</h:panelGrid>


			<h:messages globalOnly="true" layout="table" />


			<h:panelGroup id="result">
				<h:dataTable value="#{searchBean.searchScore}" var="item"
					bgcolor="#F1F1F1" border="2" width="90%">
					<h:column>
						<f:facet name="header">Repozytorium </f:facet>
						<h:outputText value="#{item.repo.name}" />
					</h:column>
					<h:column>
						<f:facet name="header">Tytuł </f:facet>
						<h:outputText value="#{item.book.title}" />
					</h:column>

					<h:column>
						<f:facet name="header">Autor</f:facet>
						<h:outputText value="#{item.book.author}" />
					</h:column>

		

					<h:column>
						<f:facet name="header">Kategorie </f:facet>
						<h:outputText value="#{item.book.categories}" />
					</h:column>
					<h:column>
						<f:facet name="header">Właściciel </f:facet>
						<h:outputText value="#{item.user.login}" />
					</h:column>

					<h:column>
						<f:facet name="header"></f:facet>

						<h:commandLink value="#{(item.lent==true)? 'Wypożyczona' : 'Wypożycz'}"
							action="#{searchBean.loan}" disabled="#{item.lent}">
							<f:setPropertyActionListener target="#{searchBean.selectedItem}"
								value="#{item}"  />
						</h:commandLink>

					</h:column>

				</h:dataTable>
			</h:panelGroup>
			
		</h:form>
	
</div>
</ui:composition>

</html>